package com.cxyxj.validateddemo;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author: gongj
 * @create: 2022-01-28 14:20
 */
@RestController
@Validated
public class GetHeaderController {

    /**
     *
     * @param req
     */
    @PostMapping("save")
    public void save(@RequestBody @Validated UserReq req) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();

        System.out.println( mapper.writeValueAsString(req));
    }

    @PostMapping("save2")
    public void save2(@Validated UserReq req){

    }

    @PostMapping("save3")
    public String save3(@RequestBody @Valid @NotEmpty(message = "该集合不能为空") List<UserReq> req){
        return "成功";
    }

    @PostMapping("save4")
    public String save4(@RequestBody @Validated @NotEmpty(message = "该集合不能为空") ValidList<UserReq> req){
        return "成功";
    }

    /**
     * 测试分组是否可用
     * @param req
     * @return
     */
    @PostMapping("save5")
    public String save5(@RequestBody @Validated(value = {ZfbPayGroup.class}) @NotEmpty(message = "该集合不能为空") ValidList<PayReq> req){
        return "成功";
    }

    @PostMapping("save6")
    public String save6(@RequestBody @Validated @NotEmpty(message = "该集合不能为空") ValidList<PayReq> req){
        return "成功";
    }


    @PostMapping("get")
    public void get(@NotBlank(message = "名称 is required") String name,@NotBlank(message = "邮箱 is required") String email) throws JsonProcessingException {

    }

    @PostMapping("zfbPaySave")
    public void zfbPaySave(@RequestBody @Validated(value = {ZfbPayGroup.class}) PayReq req) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();

        System.out.println( mapper.writeValueAsString(req));
    }
    @PostMapping("wxbPaySave")
    public void wxbPaySave(@RequestBody @Validated PayReq req) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();

        System.out.println( mapper.writeValueAsString(req));
    }
}
